<script setup>
import ComAffix from "@/components/ComAffix.vue";
import {ref} from "vue";
import {getNoticeByLikeAndCollect} from "@/api/notice.js";
import {humanizeTime} from "@/utiles/format.js";
import {userGetUserInfoService} from "@/api/user.js";
import router from "@/router/index.js";

const notifications = ref([
]);

const getNotices = async () => {
  const res = await getNoticeByLikeAndCollect();
  notifications.value = res.data.data
}
getNotices()
console.log(notifications)

//跳转至post页
const viewPost = async (postId,userId) => {

  const res = await userGetUserInfoService(userId)
  console.log(res.data.data)
  await router.push({
    name: 'Post',
    params: {
      id: postId,
    },
    query: {
      authorId: res.data.data.id,
      authorAvatar: res.data.data.avatar,
      authorName: res.data.data.nickname,
      authorIntroduced: res.data.data.introduced
    }
  })
}
</script>

<template>
  <div class="main">
    <el-affix :offset="0">
      <ComAffix></ComAffix>
    </el-affix>
    <div class="w">
      <div class="notice-nav">
        <span><router-link  :to="{ name: 'Notice' }">评论</router-link></span>
        <span><router-link  :to="{ name: 'NoticeLike' }">赞和收藏</router-link></span>
        <span><router-link  :to="{ name: 'NoticeFollow' }">新增关注</router-link></span>
      </div>
      <div>
        <el-card v-for="(notice,index) in notifications" :key=index  class="notification-item">

          <div class="notification-header">
            <el-avatar :size="40" :src="notice.userAvatar"/>
            <div class="user-info">
              <span class="nickname">{{ notice.userName }}</span>
              <span class="time">{{humanizeTime(notice.createTime)}}</span>
            </div>
          </div>

          <div v-if="notice.type===1">
            点赞了你的评论
            <span>{{notice.targetContent}}</span>
          </div>
          <div v-else-if="notice.type===2">
            点赞了你的帖子
          </div>
          <div v-else>
            收藏了你的帖子
          </div>

          <div>
            <span class="post-title" @click="viewPost(notice.postId,notice.userId)">{{ notice.postTitle }}</span>-->
          </div>

        </el-card>
      </div>
    </div>
  </div>
</template>

<style scoped lang="scss">
.w {
  width: 800px;
  margin: 0 auto;
}

.notice-nav {
  display: flex;
  align-items: center;
  margin: 30px 0;
  padding: 20px 20px;
  background: white;
  border-radius: 4px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);

  span {
    margin-right: 30px;
    cursor: pointer;
    color: #666;
    padding: 8px 12px;
    border-radius: 4px;

    &.active {
      background: #f0f2f5;
      color: #409eff;
      font-weight: 500;
    }

    &:hover {
      background: #f5f7fa;
    }
  }
}

.notification-item {
  margin-bottom: 16px;
  transition: all 0.3s;

  &:hover {
    transform: translateX(5px);
  }
}

.notification-header {
  display: flex;
  align-items: center;
  margin-bottom: 16px;

  .user-info {
    margin-left: 12px;

    .nickname {
      font-weight: 500;
      margin-right: 8px;
    }

    .time {
      color: #909399;
      font-size: 0.85em;
    }
  }
}

.notification-content {
  margin-left: 52px;

  .reply-text, .comment-text {
    margin: 0 0 12px;
    line-height: 1.6;
    color: #303133;
  }

  .original-comment {
    background: #f8f9fa;
    border-radius: 4px;
    padding: 12px;
    margin: 12px 0;

    .target-content {
      color: #606266;
      font-size: 0.9em;
      margin: 0;
    }
  }

  .related-post {
    display: flex;
    align-items: center;
    color: #909399;
    font-size: 0.9em;

    .post-title {
      margin-left: 8px;
      color: #409eff;
      cursor: pointer;

      &:hover {
        text-decoration: underline;
      }
    }
  }
}

.post-title {
  margin-left: 8px;
  color: #409eff;
  cursor: pointer;

  &:hover {
    text-decoration: underline;
  }
}
a {
  text-decoration: none;
  cursor: pointer;
  color: #636363;
}
</style>
